package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.Page;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.common.dto.VideoQueryParam;
import site.yunnong.atvris.common.dto.VideoUploadParam;
import site.yunnong.atvris.portal.service.UploadService;
import site.yunnong.atvris.portal.service.FrontVideoService;
import site.yunnong.atvris.service.vo.PlayerPageVO;
import site.yunnong.atvris.service.vo.VideoCardVO;
import site.yunnong.atvris.service.vo.VideoDetailsVO;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-07日
 */
@Slf4j
@Api(tags = "视频相关接口")
@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private UploadService uploadService;
    @Resource
    private FrontVideoService frontVideoService;

    @ApiOperation("上传视频")
    @PostMapping("/save")
    public ResultVO saveVideo(@RequestBody VideoUploadParam upload) {
        uploadService.uploadVideo(upload);
        return new ResultVO().success();
    }
    
    @ApiOperation("获取视频信息")
    @GetMapping("/info")
    public ResultVO videoInfo(@RequestParam("uvid") Long uvid) {
        VideoDetailsVO vo = frontVideoService.queryVideoInfoByUvid(uvid);
        return new ResultVO().success(vo);
    }
    
    @ApiOperation("获取视频播放页信息")
    @GetMapping("/player-page-info")
    public ResultVO playerPageInfo(@RequestParam("uvid") Long uvid) {
        PlayerPageVO vo = frontVideoService.queryPlayerPageInfo(uvid);
        return new ResultVO().success(vo);
    }
    
    // todo 推荐
    @ApiOperation("获取相关视频推荐")
    @GetMapping("/relative-recommend")
    public ResultVO relativeRecommend(@RequestParam(value = "uvid", required = true) Long uvid,
                                      @RequestParam(value = "pageSize", defaultValue = "20", required = true) Integer pageSize) {
        List<VideoCardVO> vo = frontVideoService.queryRecommendListByUvid(uvid, pageSize);
        return new ResultVO().success(vo);
    }
//
//    @ApiOperation("删除视频")
//    @DeleteMapping("/{videoId}")
//    public CommonResult getVideo(@PathVariable Long videoId) {
//        int count = videoService.delete(videoId);
//        LocalAssert.notZero(count, "无此视频");
//        return CommonResult.result(YunnongHttpStatus.SUCCESS);
//    }
    
    @ApiOperation("查询用户分页视频列表信息")
    @PostMapping("/list")
    public ResultVO queryUserVideoPage(@RequestBody VideoQueryParam param) {
        Page result = frontVideoService.queryUserVideoPage(param);
        return new ResultVO().success(result);
    }
//    @ApiOperation("编辑视频")
//    @PostMapping("/edit")
//    public CommonResult editVideo(@Valid @RequestBody VideoPostParam upload) {
//        int count = videoService.update(upload);
//        LocalAssert.notZero(count, "编辑视频失败");
//        return CommonResult.result(YunnongHttpStatus.NO_CONTENT);
//    }
}
